package com.huanwei.cc.ui;

import android.annotation.SuppressLint;
import android.content.Intent;
import android.view.View;
import android.widget.RelativeLayout;
import android.widget.Toast;

import com.huanwei.cc.utils.SpfUtils;
import com.huanwei.mainfragment.MainActivity;
import com.huanwei.cc.base.MyApplication;
import com.huanwei.cc.R;
import com.huanwei.cc.activity.EditNoteActivity;
import com.huanwei.mainfragment.Mine4Fragment;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

import me.shaohui.bottomdialog.BaseBottomDialog;

/**
 * Created by shaohui on 16/10/11.
 */
@SuppressLint("ValidFragment")
public class ShareBottomDialog extends BaseBottomDialog {
    MainActivity mainActivity;

    @Override
    public int getLayoutRes() {
        return R.layout.dialog_layout;
    }

    @SuppressLint("ValidFragment")
    public ShareBottomDialog(MainActivity mainActivity) {
        this.mainActivity = mainActivity;

    }

    @Override
    public void bindView(View v) {
        RelativeLayout relativeLayout = (RelativeLayout) v.findViewById(R.id.mRlWechat);
        relativeLayout.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Date now = new Date();
                SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");//可以方便地修改日期格式


                String hehe = dateFormat.format(now);
                System.out.println(hehe);

                Calendar c = Calendar.getInstance();//可以对每个时间域单独修改
                int year = c.get(Calendar.YEAR);
                int month = c.get(Calendar.MONTH);
                int date = c.get(Calendar.DATE);
                int hour = c.get(Calendar.HOUR_OF_DAY);
                int minute = c.get(Calendar.MINUTE);
                int second = c.get(Calendar.SECOND);
                String name = (String) SpfUtils.get(mainActivity, "name", "");
                shareDialog(name, year + "/" + month + "/" + date + " " + hour + ":" + minute + ":" + second);
                dismiss();

            }
        });
        RelativeLayout relativeLayout2 = (RelativeLayout) v.findViewById(R.id.mRlWeixinCircle);
        relativeLayout2.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {

                String type = (String) SpfUtils.get(MyApplication.getInstance(), "type", "1");
                if (type.equals("1")) {
                    Toast.makeText(MyApplication.getInstance(), "请登录", Toast.LENGTH_SHORT).show();
                    return;
                }
                startActivity(new Intent(MyApplication.getInstance(), EditNoteActivity.class));

//                Toast.makeText(MyApplication.getInstance(), "资料上传成功", Toast.LENGTH_SHORT).show();
                dismiss();
            }
        });

    }

    private void shareDialog(String name, String zhiye) {
        //ShareBottomDialog dialog = new ShareBottomDialog();
        //dialog.show(getSupportFragmentManager());
        EditTextDialog2 dialog = new EditTextDialog2(name, zhiye);
        dialog.show(mainActivity.getSupportFragmentManager());
    }
}
